package com.nchu.ft.common.util;

import lombok.Getter;

import java.util.Map;

public enum DimensionType {
    EXTRAVERSION("外倾性", Map.of(
            1, false,
            6, true,
            11, false,
            16, false,
            21, true,
            26, false,
            31, true,
            36, false,
            42, false
    )),

    AGREEABLENESS("宜人性", Map.of(
            2, true,
            7, false,
            12, true,
            17, false,
            22, false,
            27, true,
            32, false,
            37, true,
            43, true
    )),

    CONSCIENTIOUSNESS("责任感", Map.of(
            3, false,
            8, true,
            13, false,
            18, true,
            23, true,
            28, false,
            33, false,
            38, false
    )),

    NEUROTICISM("神经质", Map.of(
            4, false,
            9, true,
            14, false,
            19, false,
            24, true,
            29, false,
            34, true,
            39, false
    )),

    OPENNESS("开放性", Map.of(
            5, false,
            10, false,
            15, false,
            20, false,
            25, false,
            30, false,
            35, true,
            40, false,
            41, true,
            44, false
    ));

    @Getter
    private final String name;
    private final Map<Integer, Boolean> questions;

    DimensionType(String name, Map<Integer, Boolean> questions) {
        this.name = name;
        this.questions = questions;
    }

    public int calculateScore(Map<Integer, Integer> scores) {
        return questions.entrySet().stream()
                .mapToInt(e -> {
                    int qNum = e.getKey();
                    boolean reverse = e.getValue();
                    int rawScore = scores.getOrDefault(qNum, 0);
                    return reverse ? (5 - rawScore) : (rawScore + 1);
                })
                .sum();
    }
}